package jxtend.processor.eclipse.visitor.interceptor;

import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.Literal;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.lookup.Scope;

@SuppressWarnings("restriction")
public class SetMissingConstantOfExpressionInterceptor extends ASTNodeVisitorInterceptorAdapter {

	@Override
	public boolean interceptVisit(ASTNodeVisitorInterceptorContext interceptorChain, ASTNode node, Scope scope) {
		if ((node instanceof Expression) && ((Expression) node).constant == null) {
			if (node instanceof Literal) {
				((Literal) node).computeConstant();
			} else {
				((Expression) node).constant = Constant.NotAConstant;
			}
		}

		return super.interceptVisit(interceptorChain, node, scope);
	}

}
